// IResponse.cs
//
// Copyright (c) 2008 Mike Strobel
//
// This source code is subject to the terms of the Microsoft Reciprocal License (Ms-RL).
// For details, see <http://www.opensource.org/licenses/ms-rl.html>.
//
// All other rights reserved.

using System;
using System.Linq;

using Supremacy.Entities;
using Supremacy.Game;

namespace Supremacy.Diplomacy
{
    public interface IResponse
    {
        TurnNumber TurnSent { get; }
        Civilization Sender { get; }
        Civilization Recipient { get; }
        ResponseType ResponseType { get; }
        IProposal Proposal { get; }
        IProposal CounterProposal { get; }
    }

    public static class ResponseExtensions
    {
        public static bool IsThreat(this IResponse response)
        {
            return TestResponseType(response, ResponseType.Threaten);
        }

        public static bool IsCounterProposal(this IResponse response)
        {
            return TestResponseType(response, ResponseType.Counter);
        }

        public static bool IsAcceptance(this IResponse response)
        {
            return TestResponseType(response, ResponseType.Accept);
        }

        public static bool IsRejection(this IResponse response)
        {
            return TestResponseType(response, ResponseType.Reject);
        }

        public static bool IsValid(this IResponse response)
        {
            if (response == null)
                return false;
            return (response.ResponseType != ResponseType.NoResponse);
        }

        private static bool TestResponseType(IResponse response, ResponseType responseType)
        {
            if (response == null)
                return false;
            return (response.ResponseType == responseType);
        }
    }
}